home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 12.3 KB | 355 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWRect.h
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #ifndef FWRECT_H
- #define FWRECT_H
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- //========================================================================================
- // Typedefs
- //========================================================================================
-
- typedef unsigned short FW_PointSelector;
-
- const FW_PointSelector FW_kTopLeft = 0;
- const FW_PointSelector FW_kBotRight = 1;
-
- //========================================================================================
- // Forward Class Declarations
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CRect;
-
- //========================================================================================
- // Global
- //========================================================================================
-
- extern const FW_CRect FW_kZeroRect;
-
- //========================================================================================
- // Global operators << and >>
- //========================================================================================
-
- FW_FUNC_ATTR const FW_CWritableStream& operator<<(const FW_CWritableStream& stream, const FW_CRect& rect);
- FW_FUNC_ATTR const FW_CReadableStream& operator>>(const FW_CReadableStream& stream, FW_CRect& rect);
-
- //========================================================================================
- // struct FW_SPlatformRect
- //========================================================================================
-
- struct FW_CLASS_ATTR FW_SPlatformRect : public FW_PlatformRect
- {
- FW_SPlatformRect();
-
- FW_SPlatformRect(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b);
-
- FW_SPlatformRect(const FW_SPlatformPoint& topLeft, const FW_SPlatformPoint& botRight);
-
- FW_SPlatformRect(const FW_PlatformRect& plfmRect);
- FW_SPlatformRect(const FW_SPlatformRect& plfmRect);
- FW_SPlatformRect(const FW_CRect& rect);
-
- FW_SPlatformRect& operator=(const FW_SPlatformRect& plfmRect);
- FW_SPlatformRect& operator=(const FW_PlatformRect& plfmRect);
- FW_SPlatformRect& operator=(const FW_CRect& rect);
-
- const FW_SPlatformPoint& TopLeft() const;
- FW_SPlatformPoint& TopLeft();
- const FW_SPlatformPoint& BotRight() const;
- FW_SPlatformPoint& BotRight();
-
- FW_Boolean operator==(const FW_SPlatformRect& rect) const;
- FW_Boolean operator!=(const FW_SPlatformRect& rect) const;
-
- void Set(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b);
- };
-
- inline FW_SPlatformRect::FW_SPlatformRect() {left = right = top = bottom = 0;}
-
- //========================================================================================
- // class FW_CRect
- // Has the same layout as ODRect, but uses FW_CFixed instead of ODFixed
- //========================================================================================
-
- class FW_CLASS_ATTR FW_CRect
- {
- //----------------------------------------------------------------------------------------
- // Data members
- //
- public:
- FW_CFixed left;
- FW_CFixed top;
- FW_CFixed right;
- FW_CFixed bottom;
-
- //----------------------------------------------------------------------------------------
- // Constructors/Destructors
- //
- public:
- FW_CRect();
- FW_CRect(FW_CFixed l, FW_CFixed t, FW_CFixed r, FW_CFixed b);
-
- FW_CRect(const FW_PlatformRect& plfmRect);
- FW_CRect(const FW_CRect& rect);
- FW_CRect(const ODRect& rect);
-
- FW_CRect(const FW_CReadableStream& stream);
-
- FW_CRect(const FW_CPoint& topLeft, const FW_CPoint& botRight);
- FW_CRect(const FW_CPoint& startPoint, const FW_CPoint& endPoint, FW_CFixed penSize);
- FW_CRect(const FW_CPoint& topLeft, FW_CFixed width, FW_CFixed height);
-
- //----------------------------------------------------------------------------------------
- // operators
- //
- public:
- // ----- Assignement -----
- FW_CRect& operator=(const FW_CRect& rect);
- FW_CRect& operator=(const ODRect& odRect);
- FW_CRect& operator=(const FW_PlatformRect& plfmRect);
-
- // ----- Modification -----
- void operator&=(const FW_CRect& rect); // Intersect with rectangle
- void operator|=(const FW_CRect& rect); // Union with rectangle
- void operator|=(const FW_CPoint& point); // Expand to fit point
-
- // ----- Conversion -----
- // It is too dangerous to have automatic conversion. Use AsPlatformRect.
- // operator FW_PlatformRect() const;
- operator ODRect() const
- { return * (ODRect*) this; }
-
- // ----- Array -----
- FW_CPoint& operator[](FW_PointSelector sel);
- const FW_CPoint& operator[](FW_PointSelector sel) const;
-
- // ----- Testing -----
- FW_Boolean operator==( const FW_CRect& ) const;
- FW_Boolean operator!=( const FW_CRect &r ) const
- {return !(*this==r);}
-
- //----------------------------------------------------------------------------------------
- // New API
- //
- public:
- // ----- Conversion -----
- void AsPlatformRect(FW_PlatformRect& plfmRect) const;
-
- // ----- Modification -----
- void Clear();
- void Set(FW_CFixed left, FW_CFixed top, FW_CFixed right, FW_CFixed bottom);
- void Set(const FW_CPoint& topLeft, FW_CFixed width, FW_CFixed height);
- void SetInt(short left, short top, short right, short bottom);
- void Offset(FW_CFixed x, FW_CFixed y);
- void Offset(const FW_CPoint& offset);
- void Place(FW_CFixed x, FW_CFixed y);
- void Place(const FW_CPoint& offset);
- void Inset(FW_CFixed x, FW_CFixed y);
- void Map(const FW_CRect& srcRect, const FW_CRect& dstRect);
- void PlaceInCenter(const FW_CRect& srcRect);
-
- void Sort();
-
- FW_CRect& operator+=(const FW_CPoint& pt);
- FW_CRect operator+(const FW_CPoint& pt) const;
-
- FW_CRect& operator-=(const FW_CPoint& pt);
- FW_CRect operator-(const FW_CPoint& pt) const;
-
- // ----- OpenDoc Transform -----
-
- void Transform(Environment* ev, ODTransform* transform);
- void InverseTransform(Environment* ev, ODTransform* transform);
- // Modify the rectangle
-
- FW_CRect TransformCopy(Environment* ev, ODTransform* transform) const;
- FW_CRect InverseTransformCopy(Environment* ev, ODTransform* transform) const;
- // Return a modified copy
-
- // ----- Accessors -----
-
- const FW_CPoint& TopLeft() const
- {return *(FW_CPoint*)&left;}
- FW_CPoint& TopLeft()
- {return *(FW_CPoint*)&left;}
- const FW_CPoint& BotRight() const
- {return *(FW_CPoint*)&right;}
- FW_CPoint& BotRight()
- {return *(FW_CPoint*)&right;}
- FW_CFixed Width() const
- {return FW_CFixed(right-left);}
- FW_CFixed Height() const
- {return FW_CFixed(bottom-top);}
- FW_CPoint Size() const;
-
- // ----- Testing -----
- FW_Boolean IsEmpty() const;
- FW_Boolean Contains(const FW_CPoint& point) const;
- FW_Boolean Contains(const FW_CRect& rect) const;
- FW_Boolean IsIntersecting(const FW_CRect& rect) const;
-
- // ----- Operation on Rectangle -----
- void Intersection(const FW_CRect& rect);
- void Intersection(const FW_CRect& rect1, const FW_CRect& rect2);
-
- void Union(const FW_CRect& rect);
- void Union(const FW_CRect& rect1, const FW_CRect& rect2);
- };
-
- //========================================================================================
- // Inlines
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::FW_SPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformRect::FW_SPlatformRect(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b)
- {
- left = l; top = t;
- right = r; bottom = b;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::FW_SPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformRect::FW_SPlatformRect(const FW_SPlatformPoint& topLeft,
- const FW_SPlatformPoint& botRight)
- {
- #ifdef FW_BUILD_MAC
- left = topLeft.h; top = topLeft.v;
- right = botRight.h; bottom = botRight.v;
- #endif
- #ifdef FW_BUILD_WIN
- left = topLeft.x; top = topLeft.y;
- right = botRight.x; bottom = botRight.y;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::FW_SPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformRect::FW_SPlatformRect(const FW_SPlatformRect& plfmRect)
- {
- left = plfmRect.left; top = plfmRect.top;
- right = plfmRect.right; bottom = plfmRect.bottom;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::FW_SPlatformRect
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformRect::FW_SPlatformRect(const FW_PlatformRect& plfmRect)
- {
- left = plfmRect.left; top = plfmRect.top;
- right = plfmRect.right; bottom = plfmRect.bottom;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::operator=
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformRect& FW_SPlatformRect::operator=(const FW_SPlatformRect& plfmRect)
- {
- left = plfmRect.left; top = plfmRect.top;
- right = plfmRect.right; bottom = plfmRect.bottom;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::operator=
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformRect& FW_SPlatformRect::operator=(const FW_PlatformRect& plfmRect)
- {
- left = plfmRect.left; top = plfmRect.top;
- right = plfmRect.right; bottom = plfmRect.bottom;
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::Set
- //----------------------------------------------------------------------------------------
- inline void FW_SPlatformRect::Set(FW_PlatformCoordinate l, FW_PlatformCoordinate t,
- FW_PlatformCoordinate r, FW_PlatformCoordinate b)
- {
- left = l; top = t;
- right = r; bottom = b;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::TopLeft
- //----------------------------------------------------------------------------------------
- inline const FW_SPlatformPoint& FW_SPlatformRect::TopLeft() const
- {
- return *(FW_SPlatformPoint*)this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::TopLeft
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint& FW_SPlatformRect::TopLeft()
- {
- return *(FW_SPlatformPoint*)this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::BotRight
- //----------------------------------------------------------------------------------------
- inline const FW_SPlatformPoint& FW_SPlatformRect::BotRight() const
- {
- #ifdef FW_BUILD_MAC
- return *(FW_SPlatformPoint*)⊥
- #endif
- #ifdef FW_BUILD_WIN
- return *(FW_SPlatformPoint*)&right;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_SPlatformRect::BotRight
- //----------------------------------------------------------------------------------------
- inline FW_SPlatformPoint& FW_SPlatformRect::BotRight()
- {
- #ifdef FW_BUILD_MAC
- return *(FW_SPlatformPoint*)⊥
- #endif
- #ifdef FW_BUILD_WIN
- return *(FW_SPlatformPoint*)&right;
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRect:: operator&=
- //----------------------------------------------------------------------------------------
- inline void FW_CRect:: operator&=(const FW_CRect &r)
- {
- Intersection(r);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRect:: operator|=
- //----------------------------------------------------------------------------------------
- inline void FW_CRect:: operator|= (const FW_CRect &r)
- {
- Union(r);
- }
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export off
- #endif
-
- #endif
-